<?php View::render('admin/layouts/shopMeta');?>
<link rel="stylesheet" type="text/css" href="<?php echo Router::getBaseUrl(); ?>/assets/js/webuploader.css" />
<body>
    <style>
        .u-up-hide{overflow: hidden; height: 0;}
    </style>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-member-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">文章标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="<?php echo $info ? $info['title'] : ''; ?>" placeholder="" name="title">
			</div>
		</div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>文章内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea id="editor" type="text/plain" style="width:100%;height:400px;" name="content"><?php echo $info ? $info['content'] : ''; ?></textarea>
            </div>
        </div>
        <!-- <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>分类：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                <select class="select" size="1" name="category_id">
                    <?php if ($categoryList) {
	foreach ($categoryList as $category) {?>
                    <option value="<?php echo $category['categoryId']; ?>" <?php echo $info && $info['category_id'] == $category['categoryId'] ? 'selected="selected"' : ''; ?> ><?php echo $category['name']; ?></option>
                    <?php }}?>
                </select>
                </span>
            </div>
        </div> -->
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">文章标签：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                <select class="select" size="1" name="tag" id="tag">
                    <option value=''>选择标签</option>
                    <?php foreach ($tag as $vo) {?>
                    <option value="<?php echo $vo['id'] . '_' . $vo['title']; ?>" <?php echo $info['tag_id'] == $vo['id'] ? 'selected="selected"' : ''; ?> ><?php echo $vo['title']; ?></option>
                    <?php }?>
                </select>
                </span>
            </div>
        </div>
         <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>封面图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="clearfix">
                    <div class="">
                        <a id="j-upload">上传图片</a>
                    </div>
                    <div id="j-file" class="am-margin-top am-cf">
                    <?php if ($info && $info['image']) {?>
                    <div class="f-l mr-10 j-u-box">
                        <a href="javascirpt:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>
                        <input type="hidden" name="image" value="<?php echo $info['image']; ?>" />
                        <a href="javascript:;"><img class="thumbnail" src="<?php echo $info['image']; ?>"  style="width:100px;height:100px" /></a>
                    </div>
                    <?php }?>
                    </div>
                </div>
                <span>图片大小:320px*640px</span>
            </div>
        </div>

        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">文章类型：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
				<select class="select" size="1" name="type" id="j_type">
                    <option value="1" <?php echo $info['type'] == 1 ? 'selected="selected"' : ''; ?> >图文</option>
                    <option value="2" <?php echo $info['type'] == 2 ? 'selected="selected"' : ''; ?> >视频</option>
				</select>
				</span>
            </div>
		</div>
        <div class="row cl type type_1 u-up-hide">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片列表：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="clearfix">
                    <div class="">
                        <a id="j-upload-avatar">上传图片</a>
                    </div>
                    <div id="j-file-avatar" class="">
                    <?php if ($info && $info['image_list']) {$imageList = explode('$$$', $info['image_list']);foreach ($imageList as $image) {?>
                    <div class="f-l mr-10 j-u-box">
                        <a href="javascirpt:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>
                        <input type="hidden" name="image_list[]" value="<?php echo $image; ?>" />
                        <a href="javascript:;"><img class="thumbnail" src="<?php echo $image; ?>"  style="width:100px;height:100px" /></a>
                    </div>
                    <?php }}?>
                    </div>
                </div>
                <span>图片大小:640px*320px</span>
			</div>
		</div>
        <div class="row cl type type_2 u-up-hide">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>上传视频：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<div class="clearfix">
                    <div class="">
                        <a id="j-upload-v">上传视频</a>
                    </div>
                    <div id="j-file-video" class="">
                    <?php if ($info && $info['video_url']) {?>
                    <div class="f-l mr-10 j-u-box">
                        <a href="javascirpt:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>
                        <!-- <input type="hidden" name="image" value="<?php echo $info['image']; ?>" /> -->
                        <input type="hidden" name="gif_image" value="<?php echo $info['gif_image']; ?>" />
                        <input type="hidden" name="video_url" value="<?php echo $info['video_url']; ?>" />
                        <a href="javascript:;"><img class="thumbnail" src="<?php echo $info['image']; ?>"  style="width:100px;height:100px" /></a>
                    </div>
                    <?php }?>
                    </div>
                </div>
                <span>视频大小:50M以内</span>
			</div>
		</div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">审核状态：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                <select class="select" size="1" name="status" id="status">
                    <option value="0" <?php echo $info['status'] == 0 ? 'selected="selected"' : ''; ?> >未审核</option>
                    <option value="1" <?php echo $info['status'] == 1 ? 'selected="selected"' : ''; ?> >通过</option>
                    <option value="2" <?php echo $info['status'] == 2 ? 'selected="selected"' : ''; ?> >不通过</option>
                </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>定时显示：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text Wdate" value="<?php echo $info ? date("Y-m-d H:i:s", $info['showtime']) : date("Y-m-d H:i:s"); ?>"  onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})"  placeholder="" name="showtime" id="showtime">
            </div>
        </div>
        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">点赞数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text col-sm-2" value="<?php echo $info ? $info['up_total'] : ''; ?>" placeholder="" name="up_total">
			</div>
		</div>
        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">收藏数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text col-sm-2" value="<?php echo $info ? $info['collect_total'] : ''; ?>" placeholder="" name="collect_total">
			</div>
		</div>
        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">浏览数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text col-sm-2" value="<?php echo $info ? $info['view_total'] : ''; ?>" placeholder="" name="view_total">
			</div>
		</div>
        <div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">分享数：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text col-sm-2" value="<?php echo $info ? $info['share_total'] : ''; ?>" placeholder="" name="share_total">
			</div>
		</div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">绑定商品：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <select id='pre-selected-optionss' multiple='multiple'>
                <?php foreach ($goods as $key => $value): ?>
                    <option value='<?php echo $value['goods_id'] ?>' <?php if (in_array($value['goods_id'], $info['bind_ids'])) {echo 'selected';}?>><?php echo $value['name'] ?></option>
                <?php endforeach?>
                </select>
            </div>
        </div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
             <input type="hidden" name="bind_id" id="bind_id" value="<?php echo $info ? $info['bind_id'] : ''; ?>" />
                <input type="hidden" name="dynamicId" value="<?php echo $info ? $info['dynamic_id'] : 0; ?>" />
                <input type="hidden" name="uid" value="<?php echo $info ? $info['uid'] : $uid; ?>" />
                <input type="hidden" name="user_type" value="2" />
                <input class="btn btn-primary radius" type="button" id="j_submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
</body>
<?php View::render('admin/layouts/footer');?>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/ueditor.config.js?v=123"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/ueditor.all.min.js?v=123"> </script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js?v=123"></script>
<script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/assets/js/webuploader.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="<?php echo Router::getBaseUrl(); ?>/lib/lou-multi-select-e052211/css/multi-select.css">
 <!-- Bootstrap JavaScript -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/js/bootstrap.min.js"></script>
  <script type="text/javascript" src="<?php echo Router::getBaseUrl(); ?>/lib/lou-multi-select-e052211/js/jquery.multi-select.js"></script>
<script type="text/javascript">
$(function(){
    Array.prototype.indexOf = function(val) {
for (var i = 0; i < this.length; i++) {
if (this[i] == val) return i;
}
return -1;
};
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};
     $('#pre-selected-optionss').multiSelect({
      afterSelect: function(values){
        var temp=new Array();
        var band=$('#bind_id').val();
        if(band){
            temp=band.split(',')
        }
        temp.push(values);
        band=temp.join(",");
        $('#bind_id').val(band);
      },
      afterDeselect: function(values){
        var temp=new Array();
        var band=$('#bind_id').val();
        if(band){
            temp=band.split(',')
        }
         temp.remove(values);
            band=temp.join(",");
            $('#bind_id').val(band);
      }
    });
formData = {}
$.getJSON('/oss/getImageToken', function(ret){
    var data = ret.data;
    formData = {
      'key' : data.dir,
      'policy': data.policy,
      'OSSAccessKeyId': data.accessid,
      'success_action_status' : '200', //让服务端返回200,不然，默认会返回204
      'callback' : '',
      'signature': data.signature,
      'domain': data.domain,
      'host':data.host
    };
});
formDataVideo = {}
$.getJSON('/oss/getVideoToken', function(ret){
    var data = ret.data;
    formDataVideo = {
      'key' : data.dir,
      'policy': data.policy,
      'OSSAccessKeyId': data.accessid,
      'success_action_status' : '200',
      'callback' : '',
      'signature': data.signature,
      'domain': data.domain,
      'host':data.host
    };
});
    $('#j_type').on('change', function(){
        var type=$(this).val();
        $('.type').addClass("u-up-hide");
        $('.type_'+type).removeClass("u-up-hide");
    });
    var type=$('#j_type').val();
    $('.type').addClass("u-up-hide");
    $('.type_'+type).removeClass("u-up-hide");
  $('#j_submit').click(function(){
      var $btn = $(this);
        $btn.button('loading');
        $.post('<?php echo Router::getBaseUrl(); ?>/admin_dynamic/adddaka', $('form').serialize(), function (result) {
            if (result.status == 200) {
                layer.msg(result.msg, {
                    icon: 1,
                    skin: 'u-msg',
                    time: 1800,
                }, function(){
                   var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                });
                $btn.button('reset');
                return true;
            }
            layer.msg(result.msg, {
                icon: 0,
                skin: 'u-msg',
                time: 3000,
            }, function () {

            });
            $btn.button('reset');
        }, 'json');
        return;
  });

    $('.j-u-del').on('click', function(){
        $(this).parent('div').remove();
    });

     var max_file = 1000, $list = $('#j-file');
    var uploader = WebUploader.create({
        auto:true,
        swf: '<?php echo Router::getBaseUrl(); ?>/assets/js/Uploader.swf',
        server: '<?php echo Router::getBaseUrl(); ?>/admin_upload/file',
        pick: '#j-upload',
        formData:formData,
        resize: true,
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        }
    });
    uploader.on('beforeFileQueued', function(file){
        formData.key += random_string(15)+get_suffix(file.name);
        uploader.options.server = formData.host;
        uploader.options.formData = formData;
    });

    uploader.on( 'uploadError', function( file ) {
        layer.msg('文件上传出错', {
            icon: 0,
            skin: 'u-msg',
            time: 3000,
        });
    });

    uploader.on( 'uploadSuccess', function( file,response) {
        img = formData.domain+'/'+formData.key;
        var tpl='<div class="f-l mr-10 j-u-box">\
                    <a href="javascript:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>\
                    <input type="hidden" name="image" value="'+img+'" />\
                    <img class="thumbnail" src="'+img+'" style="width:100px;height:100px" />\
                </div>';
        $list.html(tpl);
        $('.j-u-del').on('click', function(){
            $(this).parent('div').remove();
        });
    });
    var max_file = 100, $list_avatar = $('#j-file-avatar');
    var uploader_avatar = WebUploader.create({
        auto:true,
        swf: '<?php echo Router::getBaseUrl(); ?>/assets/js/Uploader.swf',
        server: '<?php echo Router::getBaseUrl(); ?>/admin_upload/file',
        pick: '#j-upload-avatar',
        formData:formData,
        resize: true,
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        }
    });
    uploader_avatar.on('beforeFileQueued', function(file){
        formData.key += random_string(10)+get_suffix(file.name);
        uploader_avatar.options.server = formData.host;
        uploader_avatar.options.formData = formData;
    });

    uploader_avatar.on( 'uploadError', function( file ) {
        layer.msg('文件上传出错', {
            icon: 0,
            skin: 'u-msg',
            time: 3000,
        });
    });

    uploader_avatar.on( 'uploadSuccess', function( file,response) {
        img = formData.domain+'/'+formData.key;
        var tpl='<div class="f-l mr-10 j-u-box">\
                    <a href="javascript:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>\
                    <input type="hidden" name="image_list[]" value="'+img+'" />\
                    <img class="thumbnail" src="'+img+'" style="width:100px;height:100px" />\
                </div>';
        $list_avatar.append(tpl);
        $('.j-u-del').on('click', function(){
            $(this).parent('div').remove();
        });
    });
    var max_file = 1000, $list_video = $('#j-file-video');
    var uploader_video = WebUploader.create({
        auto:true,
        swf: '<?php echo Router::getBaseUrl(); ?>/assets/js/Uploader.swf',
        server: '<?php echo Router::getBaseUrl(); ?>/admin_upload/video',
        formData:formDataVideo,
        pick: '#j-upload-v'
    });
    var up_layer_index;
    uploader_video.on('beforeFileQueued', function(file){
        up_layer_index = layer.load(0);
        formDataVideo.key += random_string(10)+get_suffix(file.name);
        uploader_video.options.server = formDataVideo.host;
        uploader_video.options.formData = formDataVideo;
    });

    uploader_video.on( 'uploadError', function( file ) {
        layer.close(up_layer_index);
        layer.msg('文件上传出错', {
            icon: 0,
            skin: 'u-msg',
            time: 3000,
        });
    });

    uploader_video.on( 'uploadSuccess', function( file,response) {
        layer.close(up_layer_index);
        var video = formDataVideo.domain+'/'+formDataVideo.key;
        var img = video+'?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,m_fast';
        var tpl='<div class="f-l mr-10 j-u-box">\
                    <a href="javascript:;" class="j-u-del"><i class="Hui-iconfont">&#xe6dd;</i></a>\
                    <input type="hidden" name="video_url" value="'+video+'" />\
                    <input type="hidden" name="gif_image" value="" />\
                    <img class="thumbnail" src="'+img+'" style="width:100px;height:100px" />\
                </div>';
        $list_video.html(tpl);
        $('.j-u-del').on('click', function(){
            $(this).parent('div').remove();
        });
    });

    var ue = UE.getEditor('editor');
});
</script>
</html>